package com.sr.servlet.book;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sr.entity.Book;
import com.sr.service.BookService;


/**
 * Servlet implementation class ProductEditServlet  第一个用来修改数据
 */
@WebServlet("/editBook1")
public class BookEditServlet1 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BookEditServlet1() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//要修改 先查询 通过id
		String id=request.getParameter("id");//获取要更改的id
		
		BookService bs=new BookService();
		Book b=bs.findBookById(Integer.parseInt(id));
		System.out.println(id);
		request.getSession().setAttribute("books", b);
		//获取的是括号里面的值是jsp页面的便签定义的值
		request.getRequestDispatcher("editBook.jsp").forward(request, response);//重定向要打开另一个的网址
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
